package com.adbj.sychronizedtest;

public class NotSameInstance implements Runnable{
    int count=0;
    //synchronized修饰实例方法（普通方法）  锁实例对象  new了两个实例。这就意味存在了两个不同的实例锁
    @Override
    public synchronized void run() {
        for (int i=0;i<5;i++ ) {
            System.out.println(Thread.currentThread().getName()+":"+count++);
        }
    }

    public static void main(String[] args) {
        NotSameInstance no1=new NotSameInstance();
        NotSameInstance no2=new NotSameInstance();

        Thread t1=new Thread(no1,"th1");
        Thread t2=new Thread(no2,"th2");
        t1.start();
        t2.start();
    }
}
